﻿
using Autofac;
using Ymt.Repository;
namespace YmtRpc.Domain
{
    /// <summary>
    /// 仓储实例的转发类
    /// </summary>
    public static class RepositoryHub
    {
        /// <summary>
        /// IoC容器
        /// </summary>
        private static readonly IContainer Container;

        /// <summary>
        /// 注册仓储类的实例到IoC容器
        /// </summary>
        static RepositoryHub()
        {
            ContainerBuilder builder = new ContainerBuilder();
            builder.RegisterType<ServiceMetadataRepository>().As<IServiceMetadataRepository>();
            builder.RegisterType<ServiceDependencySamplingRepository>().As<IServicedependencysamplingRepository>();
            builder.RegisterType<RpcClientconfigRepository>().As<IRpcClientconfigRepository>();
            builder.RegisterType<ServiceconfigRepository>().As<IServiceconfigRepository>();

            Container = builder.Build();
        }

        /// <summary>
        /// 服务元数据的仓储实例
        /// </summary>
        public static IServiceMetadataRepository ServiceMetadataRepository
        {
            get
            {
                return Container.Resolve<IServiceMetadataRepository>();
            }
        }

        /// <summary>
        /// 服务依赖采样数据的仓储实例
        /// </summary>
        public static IServicedependencysamplingRepository ServiceDependencySamplingRepository
        {
            get
            {
                return Container.Resolve<IServicedependencysamplingRepository>();
            }
        }

        /// <summary>
        /// RPC客户端配置的仓储实例
        /// </summary>
        public static IRpcClientconfigRepository RpcClientconfigRepository
        {
            get
            {
                return Container.Resolve<IRpcClientconfigRepository>();
            }
        }

        /// <summary>
        /// RPC服务依赖配置的仓储类实例
        /// </summary>
        public static IServiceconfigRepository ServiceconfigRepository
        {
            get
            {
                return Container.Resolve<IServiceconfigRepository>();
            }
        }

    }
}
